home *** CD-ROM | disk | FTP | other *** search
- /* Identify.c
- Each routine returns an informative C string. Here are samples. (I suggest you
- use BreakLines() to printf the longer ones.)
-
- IdentifyCompiler:
- "THINK C 6 compiled to generate 68020 and 68881 instructions,
- and use 12-byte universal-format doubles."
-
- IdentifyOwner:
- "Denis Pelli"
-
- IdentifyModel:
- "PowerBook 170"
-
- IdentifyMachine:
- "Denis Pelli’s PowerBook 170 with 68030 and 68882 running System 7.10, ROM 1024K
- version 124+6*256. Caching data & instructions."
-
- IdentifyVideo(device):
- "PowerBook 170 “Macintosh D Built-In Video” (.Display_Video_Apple_TIM) in slot 0"
-
- The computer model appears only if the slot==0, which indicates built-in video. The
- curly quotes embrace the card name, and the parentheses embrace the driver name.
- The driver's version number appears only if it's non-zero.
-
- HISTORY:
- 1/29/92 dgp wrote IdentifyCompiler.
- 2/25/92 dgp wrote IdentifyMachine.
- 8/26/92 dgp get owner and model name from the System file
- 2/20/93 dgp added ROM version
- 2/27/93 dgp merged IdentifyCompiler.c and IdentifyMachine.c into the new Identify.c,
- and added IdentifyVideo.
- 4/25/93 dgp IdentifyMachine reports 24/32-bit addressing.
- 12/14/93 dgp If THINK C compiler version is "5" I report "5 or 6.0" since Symantec
- forgot to increment the version number when they released 6.0. They
- fixed this in version 6.01.
- 3/2/94 dgp Extracted IdentifyOwner from within IdentifyMachine
- 7/28/94 dgp added support for Metrowerks CodeWarrior C compiler and PowerPC.
- Eliminated use of "#s" printf format, since it's not supported by
- Metrowerks CodeWarrior C.
- 9/5/94 dgp removed assumption in printf's that int==short.
- 9/6/94 dgp Enhanced IdentifyCompiler to specify the size of int.
- 9/6/94 dgp Disable cache checks on PowerPC, because those traps are undefined.
- 10/5/94 dgp Removed all floating point code from IdentifyCompiler().
- 11/5/94 dgp Suppressed ROM info in Identify.
- 11/9/94 dgp added IdentifyApplication().
- 1/15/94 dgp added test for version 5 of CodeWarrior
- */
- #include "VideoToolbox.h"
- #include <Traps.h> // _HWPriv
- #include "mc68881.h"
- #if UNIVERSAL_HEADERS
- #include <LowMem.h>
- #else
- #define LMGetCurApName() ((StringPtr) 0x0910)
- #define gestaltNativeCPUtype 'cput'
- enum{
- gestaltCPU601 = 0x101,
- gestaltCPU603 = 0x103,
- gestaltCPU604 = 0x104
- };
- #endif
-
- #undef __CW__
- #define __CW__ 4
- #if defined(__fourbyteints__) // this symbol first appeared in version 5.0
- #undef __CW__
- #define __CW__ 5
- #if !defined(powerc)
- #if __option(IEEEdoubles) == __ieeedoubles__ // false in CW 5.0 68k compiler
- #undef __CW__
- #define __CW__ 5.5
- #endif
- #pragma fourbyteints off
- // Surprisingly, the CW5.5 68k compiler fails this test ONLY if run on the PowerPC.
- #if __option(fourbyteints) == __fourbyteints__ // false in CW 5.0 and 5.5 68k compilers
- #undef __CW__
- #define __CW__ 6
- #endif
- #pragma fourbyteints reset
- #else
- // Can anyone devise a test to distinguish version 5.5 from 5 of the ppc compiler?
- #endif
- #endif
-
- /*
- This table was complete in summer '92, but does not include the newer models.
- However, the table is used only as a backup, when the System lacks a machine name
- string, which is a feature of System 7. Since all new machines nominally require
- System 7, it is unlikely that it will ever be necessary to look them up in
- this table.
- */
- char machineName[][20]={
- "Unknown Mac","Mac 128K","Mac XL","Mac 512KE","Mac Plus","Mac SE","Mac II"
- ,"Mac IIx","Mac IIcx","Mac SE/30","Mac Portable","Mac IIci","Unknown Mac"
- ,"Mac IIfx","Unknown Mac","Unknown Mac","Unknown Mac"
- ,"Mac Classic","Mac IIsi","Mac LC","Mac Quadra 900","PowerBook 170"
- ,"Mac Quadra 700","Mac Classic II","PowerBook 100","PowerBook 140","Quadra 950"
- ,"Unknown Mac"
- // Despite the above, it appears that System 7.5 took a step backwards and lacks
- // specific names for many machines, so I've used Gestalt Selectors List 2.8 (March '95)
- // to update the list to include all currently available Macs.
- // However, the Metrowerks CodeWarrior C 5.5 compiler complains that I've got
- // too many initializers, so I'm leaving this addition commented out for the time being.
- /*
- ,"Mac LC III"
- ,"Unknown Mac"
- ,"Mac PowerBook 210"
- ,"Mac Centris 650"
- ,"Unknown Mac"
- ,"Mac PowerBook 230"
- ,"Mac PowerBook 180"
- ,"Mac PowerBook 160"
- ,"Mac Quadra 800"
- ,"Mac Quadra 650"
- ,"Mac LC II"
- ,"Mac PowerBook Duo 250"
- ,"Power Mac 9150"
- ,"Power Mac 8100/110"
- ,"Unknown Mac"
- ,"Unknown Mac"
- ,"Unknown Mac"
- ,"Mac IIvi"
- ,"Mac Performa 600"
- ,"Unknown Mac"
- ,"Power Mac 7100/80"
- ,"Mac IIvx"
- ,"Mac Color Classic"
- ,"Mac PowerBook 165c"
- ,"Unknown Mac"
- ,"Mac Centris 610"
- ,"Mac Quadra 610"
- ,"Mac PowerBook 145,145b"
- ,"Power Mac 8100/100"
- ,"Mac LC 520"
- ,"Unknown Mac"
- ,"Unknown Mac"
- ,"Unknown Mac"
- ,"Mac Centris 660AV"
- ,"Unknown Mac"
- ,"Mac Performa 460"
- ,"Unknown Mac"
- ,"Unknown Mac"
- ,"Power Mac 8100/80"
- ,"Unknown Mac"
- ,"Unknown Mac"
- ,"Unknown Mac"
- ,"Unknown Mac"
- ,"Unknown Mac"
- ,"Mac PowerBook 180c"
- ,"Mac PowerBook 520,520c,540,540c"
- ,"Unknown Mac"
- ,"Unknown Mac"
- ,"Power Mac 6100/60"
- ,"Unknown Mac"
- ,"Mac PowerBook Duo 270c"
- ,"Mac Quadra 840AV"
- ,"Unknown Mac"
- ,"Mac LC 550/Performa550"
- ,"Unknown Mac"
- ,"Unknown Mac"
- ,"Unknown Mac"
- ,"Mac PowerBook 165"
- ,"Unknown Mac"
- ,"Unknown Mac"
- ,"Unknown Mac"
- ,"Mac TV"
- ,"Mac LC 475/Performa47x"
- ,"Unknown Mac"
- ,"Unknown Mac"
- ,"Mac LC 575"
- ,"Unknown Mac"
- ,"Mac Quadra 605"
- ,"Unknown Mac"
- ,"Unknown Mac"
- ,"Unknown Mac"
- ,"Mac LC 630/Quadra 630"
- ,"Unknown Mac"
- ,"Power Mac 6100/66"
- ,"Unknown Mac"
- ,"Mac PowerBook Duo 280"
- ,"Mac PowerBook Duo 280c"
- ,"Unknown Mac"
- ,"Unknown Mac"
- ,"Unknown Mac"
- ,"Unknown Mac"
- ,"Unknown Mac"
- ,"Unknown Mac"
- ,"Unknown Mac"
- ,"Unknown Mac"
- ,"Power Mac 7100/66"
- ,"Unknown Mac"
- ,"Unknown Mac"
- ,"Mac PowerBook 150"
- ,"Power Macintosh 700 (Q700 upgr)"
- ,"Power Macintosh 900 (Q900 upgr)"
- ,"Power Macintosh 950 (Q950 upgr)"
- ,"Power Macintosh C610 (C610 upgr)"
- ,"Power Macintosh C650 (C650 upgr)"
- ,"Power Macintosh Q610 (Q610 upgr)"
- ,"Power Macintosh Q650 (Q650 upgr)"
- ,"Power Macintosh 800 (Q800 upgr)"
- */
- };
-
- char fpuName[][32]={
- "no floating point unit","68881","68882","built-in floating point"
- ,"unknown floating point unit","Software FPU"
- };
-
- char *IdentifyCompiler(void)
- {
- static char string[200];
- char *compiler,*longs,*floating,version[4],*universal;
- double v=0;
-
- string[0]=0;
- compiler="";
- #if THINK_C
- compiler="Symantec THINK C";
- if(THINK_C==1)v=4;
- else v=THINK_C;
- #endif
- #if THINK_CPLUS
- compiler="Symantec C++";
- v=THINK_CPLUS;
- #endif
- #if applec
- compiler="MPW C";
- #endif
- #if __MWERKS__
- compiler="Metrowerks CodeWarrior C";
- if(!iscntrl(0))v=4; // bug in version 4.5 and earlier
- else v=5;
- // v=__CW__;
- #endif
- if(v>0)sprintf(version,"%.0f ",v);
- else sprintf(version,"");
- if(mc68020)longs="68020";
- else{
- #if __powerc
- longs="PowerPC";
- #else
- longs="68000";
- #endif
- }
- if(mc68881)floating=" and 68881";
- else floating="";
- universal="";
- if(sizeof(double)==12){
- #if defined(THINK_C)
- #if !__option(native_fp)
- universal="\"universal\"-format ";
- #endif
- #endif
- }
- sprintf(string,"Compiled by %s %sfor %s%s, using %ld-byte int and %s%ld-byte double."
- ,compiler,version,longs,floating,sizeof(int),universal,sizeof(double));
- return string;
- }
-
- char *IdentifyModel(void)
- {
- int error;
- long machine;
- int machines=sizeof(machineName)/sizeof(machineName[0]);
- static char string[32];
-
- string[0]=0;
- error=Gestalt(gestaltMachineType,&machine);
- if(!error){
- GetIndString((unsigned char *)string,kMachineNameStrID,machine);
- p2cstr((unsigned char *)string);
- if(strlen(string)==0){
- if(machine<0 || machine>=machines)machine=0;
- sprintf(string,"%s",machineName[machine]);
- }
- }
- return string;
- }
-
- char *IdentifyVideo(GDHandle device)
- // E.g. "PowerBook 170 “Macintosh D Built-In Video” (.Display_Video_Apple_TIM)"
- {
- static char string[256];
- long quickDraw;
-
- string[0]=0;
- Gestalt(gestaltQuickdrawVersion,&quickDraw);
- if(quickDraw<gestalt8BitQD){
- sprintf(string,"%s ",IdentifyModel());
- sprintf(string,"%s“%s”",string,"1-bit QuickDraw");
- }else{
- if(GetDeviceSlot(device)==0)sprintf(string,"%s ",IdentifyModel());
- sprintf(string,"%s“%s”",string,GDCardName(device));
- if(GDVersion(device)==0)sprintf(string,"%s (%s)",string,GDNameStr(device));
- else sprintf(string,"%s (%s version %d)"
- ,string,GDNameStr(device),(int)GDVersion(device));
- sprintf(string,"%s slot %d",string,(int)GetDeviceSlot(device));
- }
- return string;
- }
-
- char *IdentifyOwner(void)
- {
- static char string[64];
- unsigned char **owner;
-
- string[0]=0;
- owner=GetString(-16096); // Get owner's name from System file
- if(owner!=NULL && *owner[0]>0){
- memcpy(string,*owner,(*owner)[0]+1);
- p2cstr((unsigned char *)string);
- }
- return string;
- }
-
- char *IdentifyApplication(void) // Returns name of application.
- {
- static char string[32];
-
- memcpy(string,LMGetCurApName(),32);
- p2cstr((unsigned char *)string);
- return string;
- }
-
- char *IdentifyMachine(void)
- {
- int error;
- long fpu,processor,system,value;
- int fpus=sizeof(fpuName)/sizeof(fpuName[0]);
- static char string[256];
- Boolean cacheData=1,cacheInstructions=1;
- long romSize,romVersion,qD;
- char *processorName,*owner;
-
- string[0]=0;
- error=Gestalt(gestaltSystemVersion,&system);
- if(error)return string; /* Gestalt not available */
- error=Gestalt(gestaltNativeCPUtype,&processor);
- if(error)Gestalt(gestaltProcessorType,&processor);
- Gestalt(gestaltFPUType,&fpu);
- if(fpu<0 || fpu>=fpus)fpu=fpus-2;
- if(fpu==1 && Gestalt('FPUE',&value)==0)fpu=fpus-1;// Software FPU by John Neil & Assoc.
- owner=IdentifyOwner();
- if(strlen(owner)>0)sprintf(string,"%s’s ",owner);
- sprintf(string,"%s%s",string,IdentifyModel());
- switch(processor){
- case 1: processorName="68000";break;
- case 2: processorName="68010";break;
- case 3: processorName="68020";break;
- case 4: processorName="68030";break;
- case 5: processorName="68040";break;
- case gestaltCPU601: processorName="PPC601";break;
- case gestaltCPU603: processorName="PPC603";break;
- case gestaltCPU604: processorName="PPC604";break;
- default: processorName="unknown processor";break;
- }
- sprintf(string,"%s with %s and %s running System %lx.%lx"
- ,string,processorName,fpuName[fpu],system/0x100,system%0x100/0x10);
- system%=0x10;
- if(system)sprintf(string,"%s.%lx",string,system);
- sprintf(string,"%s.",string);
- Gestalt(gestaltROMSize,&romSize);
- Gestalt(gestaltROMVersion,&romVersion);
- // I've never found any use for the ROM info, so I'm suppressing it.
- if(0)sprintf(string,"%s, %ldK ROM version %ld+%ld*256."
- ,string,romSize/1024,romVersion%256,romVersion/256);
- if(TrapAvailable(_HWPriv)){
- #if !__powerc /* apparently these functions don't work on PowerPC */
- cacheData=SwapDataCache(1);
- SwapDataCache(cacheData);
- cacheInstructions=SwapInstructionCache(1);
- SwapInstructionCache(cacheInstructions);
- if(cacheData || cacheInstructions)sprintf(string,"%s Caching",string);
- else sprintf(string,"%s No caching",string);
- if(cacheData)sprintf(string,"%s data",string);
- if(cacheData && cacheInstructions)sprintf(string,"%s &",string);
- if(cacheInstructions)sprintf(string,"%s instructions",string);
- sprintf(string,"%s.",string);
- #endif
- }
- value=0;
- Gestalt(gestaltAddressingModeAttr,&value);
- if(value&1<<gestalt32BitAddressing)sprintf(string,"%s 32-bit addressing.",string);
- else sprintf(string,"%s 24-bit addressing.",string);
- Gestalt(gestaltQuickdrawVersion,&qD);
- switch(qD/0x100){
- case 0:
- sprintf(string,"%s 1-bit QuickDraw.",string);
- break;
- case 1:
- sprintf(string,"%s 8-bit QuickDraw.",string);
- break;
- case 2:
- sprintf(string,"%s 32-bit QuickDraw 1.%02lx.",string,qD%0x100);
- break;
- default:
- sprintf(string,"%s QuickDraw 0x%lx.",string,qD);
- break;
- }
- return string;
- }
-